import { action, observable, observe } from 'mobx'
import { fromJS } from 'immutable'
import axios from 'axios'
import { ajax } from '../api'

interface Userinfo {
    username: string,
    role: number
}

class MyInfo {
    @observable userInfo: any = {
        // username:'',
        // role:0
    }
    @observable userList = []

    @observable annoList = []
    //维修
    @observable weixiuList: Array<object> = []

    //收费项目
    @observable freeList: Array<object> = []


    //意见列表
    @observable adviseList = []

    @observable executiveList = []

    //装修列表
    @observable finishList = []

    @observable collapsed = false
    @observable flag = false
    @action changeMyInfo = (payload:any)=>{
       this.userInfo = {...this.userInfo,...payload}
        //方法二
        //    this.userInfo = payload

    }
   


    @action getUserInfoAsync =async (payload: any)=>{
        let {code,result}:any = await ajax.getuserinfo(payload)
        if(code==200){
            this.userList = result
        }
    }
    @action getUserListAsync =async (payload: any)=>{
        let {code,result}:any = await ajax.getuserlist(payload)
        if(code==200){
            this.userList = result
        }
    }
    @action getUserList = (payload: any) => {
        this.userList = payload
    }

    //收费
    @action getFreeListAsync = async (payload: any) => {
       let {code,result}:any =await ajax.getshoufeilist(payload)
       if(code==200){

           this.freeList=result
           
       }
    }

  

    @action getAnnoListAsync = async (payload: any) => {
        let { code, result }: any = await ajax.getnoticelist(payload)
        if (code == 200) {
            this.annoList = result
        }
    }
    @action getExecutiveListAsync = async (payload: any) => {
        let { code, result }: any = await ajax.executiveList(payload)
        if (code == 200) {
            this.executiveList = result
        }
    }
    @action getAnnoList = (payload: any) => {
        this.annoList = payload
    }

   


    @action getAdviseListAsync = async (payload: any) => {
        let { code, result }: any = await ajax.getadviselist(payload)
        if (code == 200) {
            this.adviseList = result
        }
    }
    @action getAdviseList = (payload: any) => {
        this.adviseList = payload
    }

    @action changeCollapsed = ()=>{ 
        this.collapsed = !this.collapsed
    }
   
    @action changeFlag = ()=>{ 
        this.flag = !this.flag
    }

    @action getWeixiuListAsync =async (payload: any)=>{
        let {code,result}:any = await ajax.getweixiulist(payload)
        if(code==200){
            this.weixiuList = result
        }
    }

    @action getWeixiuList = (payload: any) => {
        this.weixiuList = payload
    }

    //装修
    @action getFinishListAsync =async (payload: any)=>{
        let {code,result}:any = await ajax.getfinishlist(payload)
        if(code==200){
            this.finishList = result
        }
    }

    @action getFinishList = (payload:any)=>{
        this.finishList = payload
    }
    @action getFreeList=(payload:any)=>{
        this.freeList = payload
    }
}
const myinfo = new MyInfo()
export default myinfo